/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code4 {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> ret = new ArrayList<>();
        dfs(root,0,ret);
        return ret;
    }

    public void dfs(TreeNode root,int dpth,List<Integer> ret) {
        if(root == null) {
            return;
        }
        if(dpth == ret.size()) {
            ret.add(root.val);
        }

        dfs(root.right,dpth+1,ret);
        dfs(root.left,dpth+1,ret);

    }
}